require 'tk'

def packing(x,y,side=:left,anchor=:n)
	{
		padx:x,pady:y,side:side.to_s,anchor:anchor.to_s
	}
end

root = TkRoot.new(title:"Telnet session")
top = TkFrame.new(root)
fr1 = TkFrame.new(top)
fr1a = TkFrame.new(fr1)
fr1b = TkFrame.new(fr1)
fr2 = TkFrame.new(top)
fr3 = TkFrame.new(top)
fr4 = TkFrame.new(top)

lab_pack = packing(5,5,:top,:w)
entry_pack = packing(5,2,:top)
btn_pack = packing(15,2,:left,:center)
frame_pack = packing(2,2,:top)
frame_sub_pack = packing(2,2)

var_host,var_port,var_user,var_pwd = Array.new(4){TkVariable.new}

TkLabel.new(fr1a){
	text "Host name"
	pack lab_pack
}

TkEntry.new(fr1a){
	textvariable var_host
	font "Arial 10"
	pack entry_pack
}

TkLabel.new(fr1b){
	text "Port"
	pack lab_pack
}

TkEntry.new(fr1b){
	width 2
	textvariable var_port
	font "Arial 10"
	pack entry_pack
}

TkLabel.new(fr2){
	text "User name"
	pack lab_pack
	#pack packing(5,5)
}
TkEntry.new(fr2){
	width 23
	font "Arial 12"
	textvariable var_user
	pack entry_pack
	#pack packing(5,2)
}

TkLabel.new(fr3){
	text "Password"
	pack lab_pack
}
TkEntry.new(fr3){
	width 23
	show "*"
	textvariable var_pwd
	font "Arial 12"
	focus
	pack entry_pack
}

TkButton.new(fr4){
	text "Sign on"
	command {
		printf "host:%s\nport:%d\nuser:%s\npwd:%s\n"%\
			[var_host.value,var_port.value,var_user.value,
				var_pwd.value]
	}
	pack btn_pack
}
TkButton.new(fr4){
	text "Cancel"
	command proc {exit}
	pack btn_pack
}

top.pack frame_pack
fr1.pack frame_pack
fr1a.pack frame_sub_pack
fr1b.pack frame_sub_pack
fr2.pack frame_pack
#fr2.pack packing(2,2)
fr3.pack frame_pack
fr4.pack frame_pack

var_host.value = "addison-wesley.com"
var_user.value = "hopy"
var_port.value = 23

Tk.mainloop